<template>
  <a-layout class="card" v-if="objData.cardDataList.length > 0">
    <a-layout-content>
      <a-row class="card-list" :gutter="15">
        <a-col :span="8" v-for="(item, index) in objData.cardDataList" :key="index">
          <div>
            <div class="card-list-title">
              <p class="name">{{ item.nodeName }}</p>
              <a-dropdown @select="funDelNode($event, item)">
                <IconMoreVertical></IconMoreVertical>
                <template #content>
                  <a-doption :value="{ value: 'copy' }"><IconCopy /> 复 制</a-doption>
                  <a-doption :value="{ value: 'edit' }"><IconEdit /> 编 辑</a-doption>
                  <a-doption :value="{ value: 'del' }"><IconDelete /> 删 除</a-doption>
                </template>
              </a-dropdown>
            </div>
            <div class="card-list-img">
              <img v-if="item.filepath" :src="healthStore.fileServer.value + item.filepath" />
              <img v-else src="../../assets/image/treePicture.jpg" />
            </div>
            <div class="card-list-footer">
              <p><IconSchedule class="card-list-icon" /> {{ dayjs(item.createdTime).format('YYYY-MM-DD HH:mm:ss') }}</p>
              <p @click="funCheckDetail(item)">查看详情 <IconArrowRight></IconArrowRight></p>
            </div>
          </div>
        </a-col>
      </a-row>
    </a-layout-content>
    <a-layout-footer>
      <a-pagination
        :total="objData.total"
        :current="objData.currentPage"
        :page-size="objData.pageSize"
        show-page-size
        show-total
        show-jumper
        @change="handleCurrentChange"
        @page-size-change="handleSizeChange"
      />
    </a-layout-footer>
  </a-layout>
  <div v-else class="noData">
    <p>暂无数据</p>
  </div>
  <!-- 复制节点 -->
  <CopyFrom
    ref="copyFrom"
    :satelliteId="objData.satelliteId"
    :nodeId="objData.id"
    @funCardDataList="funCardDataList"
  ></CopyFrom>
</template>
<script setup>
import { ref, toRefs, reactive, defineEmits, defineProps, defineExpose } from 'vue'
import { useHealthStore } from '@/store/modules/health'
import { Modal, Message } from '@arco-design/web-vue'
import {
  IconSchedule,
  IconMoreVertical,
  IconArrowRight,
  IconEdit,
  IconDelete,
  IconCopy
} from '@arco-design/web-vue/es/icon'
import { apiHome } from '@/api/healthAssessment'
import CopyFrom from './copyFrom.vue'
import dayjs from 'dayjs'
const copyFrom = ref(null)
const emit = defineEmits(['funCheckDetail', 'funEditCard'])
const props = defineProps({
  parentId: {
    type: String,
    default: ''
  }
})
const healthStore = toRefs(useHealthStore())
const objData = reactive({
  cardDataList: [],
  total: 1,
  currentPage: 1,
  pageSize: 10,
  id: '', // 节点ID
  satelliteId: '' // 节点卫星ID
})
// 分页 当前页码
const handleCurrentChange = (value) => {
  objData.currentPage = value
  funCardDataList()
}
// 分页 分页每页数
const handleSizeChange = (value) => {
  objData.pageSize = value
  funCardDataList()
}
// 获取列表
const funCardDataList = () => {
  objData.cardDataList = []
  apiHome
    .getPortraitDataList(props.parentId, objData.currentPage, objData.pageSize)
    .then((res) => {
      if (res.code === 200) {
        objData.cardDataList = res.data.list
        objData.total = +res.data.total
      }
    })
    .catch(() => {})
}
// 查看详情
const funCheckDetail = (data) => {
  emit('funCheckDetail', data)
}
// 编辑 / 删除 操作
const funDelNode = (e, data) => {
  if (e.value === 'edit') {
    emit('funEditCard', data)
  } else if (e.value === 'del') {
    Modal.confirm({
      title: '提示',
      content: '是否删除当前节点？',
      modalClass: 'tipModal',
      onOk: () => {
        apiHome
          .getPortraitDel(data.id)
          .then((res) => {
            if (res.code === 200) {
              Message.success('节点删除成功!')
              funCardDataList()
            } else {
              Message.error(res.message)
            }
          })
          .catch(() => {})
      }
    })
  } else {
    objData.satelliteId = data.satelliteId
    objData.id = data.id
    copyFrom.value.handleClick()
  }
}
defineExpose({
  funCardDataList
})
</script>
<style lang="less" scoped>
.card {
  width: 100%;
  height: calc(100% - 64px);
  .arco-layout-content {
    height: 100%;
    padding: 0 15px;
    overflow: auto;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE 10+ */
    &::-webkit-scrollbar {
      display: none;
    }
    .card-list {
      height: auto;
      .arco-col {
        margin-bottom: 15px;
        > div {
          border-radius: 0 0 10px 10px;
          background-color: #112b40 !important;
          .card-list-title {
            display: flex;
            align-items: center;
            justify-content: space-between;
            p {
              margin: 15px 0;
              padding: 0 15px;
              font-size: 20px;
              color: #ffffff;
            }
            .arco-icon-more-vertical {
              margin-right: 10px;
              font-size: 22px;
              color: #ffffff;
              cursor: pointer;
            }
          }
          .card-list-img {
            height: 168px;
            width: 100%;
            text-align: center;
          }
          img {
            width: 100%;
            height: 100%;
            // object-fit: contain;
          }
          .card-list-footer {
            border-radius: 0 0 10px 10px;
            color: #ffffff;
            height: 45px;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 0 15px;
            p {
              display: flex;
              align-items: center;
              margin: 10px 0;
              .card-list-icon {
                font-size: 22px;
                margin-right: 5px;
              }
              &:last-child {
                cursor: pointer;
              }
              .arco-icon-arrow-right {
                font-size: 19px;
                margin-left: 5px;
              }
            }
          }
        }
      }
    }
  }
  .arco-layout-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 5px 20px;
  }
}
.noData {
  display: flex;
  align-items: center;
  justify-content: center;
  height: calc(100% - 48px);
  font-size: 16px;
}
</style>
